<?php $this->load->view('header'); ?>
<?php
if($msg = $this->session->flashdata('flash_message'))
{
    var_dump($msg);
}
?>
    <div class="wrap-content wrap-project">
        <div class="container">
            <div class="detail-profile">
                <div class="border col-md-1 col-xs-1"></div>
				<div class="container">
					<div class="row title-project">
						<h1><?php echo $this->lang->line("create_portfolio") ?></h1>
					</div>
				</div>
                <div class="col-lg-12">
                <form method="POST" id="form-portfolio-post" enctype="multipart/form-data">
                	<?php echo form_token();?>
                    <div class="row">
                    	<div class="control-group form-group">
							<label class="control-label col-md-3"><?php echo $this->lang->line('title'); ?></label>
							<div class="controls col-md-8">
								<input type="text" class="form-control" name="title" value="<?php echo set_value('title'); ?>"/>
								<?php echo form_error('title'); ?>
							</div>
						</div>
						<div class="control-group form-group">
							<label class="control-label col-md-3"><?php echo $this->lang->line('description'); ?></label>
							<div class="controls col-md-8">
								<textarea class="form-control" id="description" name="description"
                                          rows="10" ><?php echo set_value('description');?></textarea>
                                <?php echo form_error('description')?>
							</div>
						</div>
						<div class="control-group form-group">
							<label class="control-label col-md-3"><?php echo $this->lang->line('category'); ?></label>
							<div class="controls col-md-8">
							<?php 
								/* if(isset($categories) and $categories->num_rows()>0) {   
									foreach($categories->result() as $category) {
										echo "<label><input type='checkbox'>" . $category->category_name . "</label>";
									} 
								}  */
							?>
							
								<ul class="portfolio-skill">
				                    <?php
				                        if(count($groupCategories) > 0){
				                            foreach($groupCategories as $item){
				                    ?>
				                    <li class="col-lg-4">
				                        <?php echo $item['group_name'];?>
				                    <?php
			                            if(!empty($item['categories'])){
				                    ?>
				                        <ul>
				                    <?php
				                            foreach($item['categories']->result() as $item_categories){
				                    ?>
				                            <li><label><input type="checkbox" name="categories[]" value="<?php echo $item_categories->id;?>"> <?php echo $item_categories->name;?></label></li>
				                    <?php
				                            }
				                    ?>
				                        </ul>
				                    <?php } ?>
				                    </li>
				                    <?php } }?>
			                    </ul>
							</div>
						</div>
						<div class="control-group form-group">
							<label class="control-label col-md-3"><?php echo $this->lang->line('thumbnail'); ?></label>
							<div class="controls col-md-8">
								<div class="fileinput input-image-avatar-user fileinput-new" data-provides="fileinput">
                                    <div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 200px; height: 150px; line-height: 150px;">
                                    	<div class="fileupload-image"><i class="clip-image"></i></div>
                                    </div>
                                    <div>
                                    	<span class="btn btn-default btn-upload btn-file">
                                    	<span class="fileinput-new">Select image</span>
                                    	<span class="fileinput-exists">Change</span>
                                    	<input type="file" name="thumbnail"></span>
                                        <a href="#" class="btn btn-default btn-upload btn-file fileinput-exists" data-dismiss="fileinput">Remove</a>
                                    </div>
                                    <?php echo form_error('thumbnail');?>
                                </div>
								
								<!-- 
								<div class="fileinput fileinput-new col-lg-12 col-sm-12 col-md-12 col-xs-12"
	                                 data-provides="fileinput">
	                                <div class="btn btn-default btn-lg btn-upload btn-file"><span class="fileinput-new">Upload file</span>
	                                    <span class="fileinput-exists">Change</span>
	                                    <input type="file" name="thumbnail">
	                                </div>
	                                <div class="col-lg-12 col-sm-12 col-md-12 file-item">
	                                    <div class="fileinput-filename col-lg-11 col-sm-12 col-md-12 col-xs-12"></div>
	                                    
	                                    <a href="#" class="close fileinput-exists clip-close-3" data-dismiss="fileinput"
	                                       style="float: none;font-size: 28px;line-height: 40px;"></a>
	                                </div>
	                                <?php //echo form_error('thumbnail');?>
	                            </div>
	                             -->
							</div>
						</div>
						<div class="control-group">
							<label class="control-label col-md-3"></label>
	                        <div class="controls col-md-8">
	                        	<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
	                            	<button type="submit" name="createPortfolio" value="createPortfolio" class="btn btn-lg dang_du_an col-lg-3 col-md-3 col-sm-4 col-xs-12"><i class="icon_upload"></i><?php echo $this->lang->line('Submit')?></button>
	                            </div>
	                        </div>
                        </div>
                    </div>
                </form>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#form-portfolio-post").validate({
            	errorElement: "span", // contain the error msg in a span tag
                errorClass: 'help-block',
                errorPlacement: function (error, element) { // render error placement for each input type
                    if (element.attr("type") == "radio" || element.attr("type") == "checkbox") { // for chosen elements, need to insert the error after the chosen container
                        error.insertAfter($(element).closest('.form-group').children('div').children().last());
                    } else if (element.attr("name") == "dd" || element.attr("name") == "mm" || element.attr("name") == "yyyy") {
                        error.insertAfter($(element).closest('.form-group').children('div'));
                    } else {
                        error.insertAfter(element);
                        // for other inputs, just perform default behavior
                    }
                },
                highlight: function (element) {
                    $(element).closest('.help-block').removeClass('valid');
                    // display OK icon
                    $(element).closest('.form-group').removeClass('has-success').addClass('has-error').find('.symbol').removeClass('ok').addClass('required');
                    // add the Bootstrap error class to the control group
                },
                unhighlight: function (element) { // revert the change done by hightlight
                    $(element).closest('.form-group').removeClass('has-error');
                    // set error class to the control group
                },
                success: function (label, element) {
                    label.addClass('help-block valid');
                    // mark the current input as valid and display OK icon
                    $(element).closest('.form-group').removeClass('has-error').addClass('has-success').find('.symbol').removeClass('required').addClass('ok');
                },
                rules:{
                    "title" : {
                        required : true
                    },
                    "description" : {
                        required : true
                    },
                    "categories" : {
                        required : true
                    },
                    "add" : {
                        required : true,
                        accept: "image/jpeg, image/pjpeg, image/png"
                    }
                },
                messages:{
                    "title":{
                        required : "<?php echo $this->lang->line('title_validate') ?>",
                    },
                    "description":{
                        required : "<?php echo $this->lang->line('description_validate') ?>",
                    },
                    "categories":{
                        required : "<?php echo $this->lang->line('categories_validate') ?>",
                    },
                    "add" : {
                        required : "<?php echo $this->lang->line('add_validate') ?>"
                    }
                }
            });
        });

    </script>
<?php $this->load->view('footer'); ?>